home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
lcppb.zip
/
LCPP08.ZIP
/
MAKETXT.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-08
|
1KB
|
57 lines
// maketxt.cpp -- Create a new text file
//#include <stream.hpp>
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* -- Function prototypes */
void error(const char *message);
void instruct(void);
main(int argc, char *argv[])
{
FILE *fp;
char s[129];
if (argc == 1) instruct();
cout << "\nCreating file " << argv[1];
cout << "\nEnter a blank line to end\n\n";
fp = fopen(argv[1], "w");
if (!fp) error("Creating file");
while (strlen(gets(s)) > 0) {
fputs(s, fp);
fputc('\n', fp);
}
fclose(fp);
}
/* -- Display error message and exit */
void error(const char *message)
{
// cout << form("\n\nERROR: %s\n\n", message);
printf("\n\nERROR: %s\n\n", message);
exit(1);
}
/* -- Display instructions and exit */
void instruct(void)
{
cout << "\nMAKETXT <filename>";
cout << "\nInstructions: Enter a file name, then type";
cout << "\nlines of text. End with a blank line. Note:";
cout << "\nan existing <filename> will be erased!\n";
exit(1);
}
// Copyright (c) 1990 by Tom Swan. All rights reserved
// Revision 1.00 Date: 10/06/1990 Time: 02:14 pm
// Revision 1.01 Date: 07/08/1991 Time: 05:41 pm
// Converted for Borland C++ 2.0